home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / source / src / arith / isparc_PLACEdiv.s < prev    next >
Encoding:
Text File  |  1994-11-16  |  5.6 KB  |  337 lines

  1. ! Modified by Ralf Dentzer, Heidelberg, 4.8.92 to use it as PLACEdiv
  2.  
  3. ! PLACE PLACEdiv(PLACE h, PLACE l, PLACE n, PLACE *q)
  4. !    /* h*RADIX+l / n ergibt Quotient *q, return Rest */
  5. !       /* Division mit Rest
  6. !             Voraussetzung:     h < n                */
  7.  
  8. ! Aenderungen bei der Rueckgabe des Ergebnisses:
  9. !    d -> %o0    streiche [%o3]    (alt)
  10. !    e -> [%o3]    Ersetze %o4 durch %o3
  11.  
  12. ! Now the original.
  13.  
  14. ! This division routine is the result of the joint effort of Henri Cohen
  15. ! (Talence) and Dik Winter (Amsterdam). Note that if you are interested
  16. ! only in 63 bit/ 31 bit division, a lot of the code can be suppressed
  17. ! (keep only the Lsmalldiv part). In any case the result gives a 32 bit
  18. ! quotient and remainder.
  19. ! It is not difficult to modify the code so as to obey a different
  20. ! C-calling sequence than the one given below.
  21.  
  22. !
  23. !    routine to compute (a*2^32 + b) mod c (d)
  24. !               (a*2^32 + b) / c (e)
  25. !    Note: a < c
  26. !
  27. !    Assemble with:    as -o longdiv.o -P longdiv.s
  28. !    or some such; note the -P flag to invoke the c preprocessor.
  29. !
  30. !    C call sequence:
  31. !    longdiv(a,b,c,d,e) int a,b,c,*d,*e;
  32. !
  33. !    a, b and c are assumed to be in %o0, %o1 and %o2 resp.
  34. !    the addresses of d and e are assumed to be in %o3 and %o4.
  35. !    this routine uses %o0,%o1,%o2,%o3,%o4 and %o5
  36. !
  37. !    The macros below define the addition steps and subtraction steps
  38. !    performed.
  39.  
  40. #define    SS0(label) \
  41.     addx    %o0,%o0,%o0;\
  42.     subcc    %o0,%o2,%o5;\
  43.     bcc    label;\
  44.     addxcc    %o1,%o1,%o1
  45.  
  46. #define    SS1(label) \
  47.     addx    %o5,%o5,%o5;\
  48.     subcc    %o5,%o2,%o0;\
  49.     bcc    label;\
  50.     addxcc    %o1,%o1,%o1
  51.  
  52. !    .globl    _longdiv
  53. !_longdiv:
  54.     .globl _PLACEdiv
  55. _PLACEdiv:
  56.     addcc    %o2,%o2,%g0
  57.     bcc    Lsmalldiv
  58.     andcc    %o2,1,%g0
  59.     be    Levendiv
  60.     srl    %o2,1,%o2
  61.     add    %o2,1,%o2
  62.     subcc    %o0,%o2,%o5
  63.     bcc    Lb01
  64.     addxcc    %o1,%o1,%o1
  65. La01:    SS0(Lb02)
  66. La02:    SS0(Lb03)
  67. La03:    SS0(Lb04)
  68. La04:    SS0(Lb05)
  69. La05:    SS0(Lb06)
  70. La06:    SS0(Lb07)
  71. La07:    SS0(Lb08)
  72. La08:    SS0(Lb09)
  73. La09:    SS0(Lb10)
  74. La10:    SS0(Lb11)
  75. La11:    SS0(Lb12)
  76. La12:    SS0(Lb13)
  77. La13:    SS0(Lb14)
  78. La14:    SS0(Lb15)
  79. La15:    SS0(Lb16)
  80. La16:    SS0(Lb17)
  81. La17:    SS0(Lb18)
  82. La18:    SS0(Lb19)
  83. La19:    SS0(Lb20)
  84. La20:    SS0(Lb21)
  85. La21:    SS0(Lb22)
  86. La22:    SS0(Lb23)
  87. La23:    SS0(Lb24)
  88. La24:    SS0(Lb25)
  89. La25:    SS0(Lb26)
  90. La26:    SS0(Lb27)
  91. La27:    SS0(Lb28)
  92. La28:    SS0(Lb29)
  93. La29:    SS0(Lb30)
  94. La30:    SS0(Lb31)
  95. La31:    SS0(Lb32)
  96. La32:    addx    %o0,%o0,%o0
  97. Lcommon:
  98.     xor    %o1,-1,%o1
  99.     add    %o2,%o2,%o2
  100.     sub    %o2,1,%o2
  101.     addcc    %o1,%o0,%o0
  102.     bcc    1f
  103.     subcc    %o0,%o2,%o5
  104.     subcc    %o5,%o2,%o0
  105.     bcs    2f
  106.     add    %o1,1,%o1
  107.     add    %o1,1,%o1
  108. !3:    st    %o1,[%o4]
  109. !    retl
  110. !    st    %o0,[%o3]
  111. ! RD, start
  112. 3:    retl
  113.     st    %o1,[%o3]
  114. ! RD, end
  115. 1:    bcs    3b
  116.     nop
  117.     add    %o1,1,%o1
  118. !2:    st    %o1,[%o4]
  119. !    retl
  120. !    st    %o5,[%o3]
  121. ! RD, start
  122. 2:    mov    %o5, %o0
  123.     retl
  124.     st    %o1,[%o3]
  125. ! RD, end
  126.  
  127. Lb01:    SS1(La02)
  128. Lb02:    SS1(La03)
  129. Lb03:    SS1(La04)
  130. Lb04:    SS1(La05)
  131. Lb05:    SS1(La06)
  132. Lb06:    SS1(La07)
  133. Lb07:    SS1(La08)
  134. Lb08:    SS1(La09)
  135. Lb09:    SS1(La10)
  136. Lb10:    SS1(La11)
  137. Lb11:    SS1(La12)
  138. Lb12:    SS1(La13)
  139. Lb13:    SS1(La14)
  140. Lb14:    SS1(La15)
  141. Lb15:    SS1(La16)
  142. Lb16:    SS1(La17)
  143. Lb17:    SS1(La18)
  144. Lb18:    SS1(La19)
  145. Lb19:    SS1(La20)
  146. Lb20:    SS1(La21)
  147. Lb21:    SS1(La22)
  148. Lb22:    SS1(La23)
  149. Lb23:    SS1(La24)
  150. Lb24:    SS1(La25)
  151. Lb25:    SS1(La26)
  152. Lb26:    SS1(La27)
  153. Lb27:    SS1(La28)
  154. Lb28:    SS1(La29)
  155. Lb29:    SS1(La30)
  156. Lb30:    SS1(La31)
  157. Lb31:    SS1(La32)
  158. Lb32:    ba    Lcommon
  159.     addx    %o5,%o5,%o0
  160.  
  161. Lsmalldiv:
  162.     addcc    %o1,%o1,%o1
  163. Lc00:    SS0(Ld01)
  164. Lc01:    SS0(Ld02)
  165. Lc02:    SS0(Ld03)
  166. Lc03:    SS0(Ld04)
  167. Lc04:    SS0(Ld05)
  168. Lc05:    SS0(Ld06)
  169. Lc06:    SS0(Ld07)
  170. Lc07:    SS0(Ld08)
  171. Lc08:    SS0(Ld09)
  172. Lc09:    SS0(Ld10)
  173. Lc10:    SS0(Ld11)
  174. Lc11:    SS0(Ld12)
  175. Lc12:    SS0(Ld13)
  176. Lc13:    SS0(Ld14)
  177. Lc14:    SS0(Ld15)
  178. Lc15:    SS0(Ld16)
  179. Lc16:    SS0(Ld17)
  180. Lc17:    SS0(Ld18)
  181. Lc18:    SS0(Ld19)
  182. Lc19:    SS0(Ld20)
  183. Lc20:    SS0(Ld21)
  184. Lc21:    SS0(Ld22)
  185. Lc22:    SS0(Ld23)
  186. Lc23:    SS0(Ld24)
  187. Lc24:    SS0(Ld25)
  188. Lc25:    SS0(Ld26)
  189. Lc26:    SS0(Ld27)
  190. Lc27:    SS0(Ld28)
  191. Lc28:    SS0(Ld29)
  192. Lc29:    SS0(Ld30)
  193. Lc30:    SS0(Ld31)
  194. Lc31:    SS0(Ld32)
  195. Lc32:    xor    %o1,-1,%o1
  196. !    st    %o1,[%o4]
  197. !    retl
  198. !    st    %o0,[%o3]
  199. ! RD, start
  200.     retl
  201.     st    %o1,[%o3]
  202. ! RD, end
  203.  
  204. Ld01:    SS1(Lc02)
  205. Ld02:    SS1(Lc03)
  206. Ld03:    SS1(Lc04)
  207. Ld04:    SS1(Lc05)
  208. Ld05:    SS1(Lc06)
  209. Ld06:    SS1(Lc07)
  210. Ld07:    SS1(Lc08)
  211. Ld08:    SS1(Lc09)
  212. Ld09:    SS1(Lc10)
  213. Ld10:    SS1(Lc11)
  214. Ld11:    SS1(Lc12)
  215. Ld12:    SS1(Lc13)
  216. Ld13:    SS1(Lc14)
  217. Ld14:    SS1(Lc15)
  218. Ld15:    SS1(Lc16)
  219. Ld16:    SS1(Lc17)
  220. Ld17:    SS1(Lc18)
  221. Ld18:    SS1(Lc19)
  222. Ld19:    SS1(Lc20)
  223. Ld20:    SS1(Lc21)
  224. Ld21:    SS1(Lc22)
  225. Ld22:    SS1(Lc23)
  226. Ld23:    SS1(Lc24)
  227. Ld24:    SS1(Lc25)
  228. Ld25:    SS1(Lc26)
  229. Ld26:    SS1(Lc27)
  230. Ld27:    SS1(Lc28)
  231. Ld28:    SS1(Lc29)
  232. Ld29:    SS1(Lc30)
  233. Ld30:    SS1(Lc31)
  234. Ld31:    SS1(Lc32)
  235. Ld32:    xor    %o1,-1,%o1
  236. !    st    %o1,[%o4]
  237. !    retl
  238. !    st    %o5,[%o3]
  239. ! RD, start
  240.     mov    %o5, %o0
  241.     retl
  242.     st    %o1,[%o3]
  243. ! RD, end
  244.  
  245.  
  246. Levendiv:
  247.     subcc    %o0,%o2,%o5
  248.     bcc    Lf01
  249.     addxcc    %o1,%o1,%o1
  250. Le01:    SS0(Lf02)
  251. Le02:    SS0(Lf03)
  252. Le03:    SS0(Lf04)
  253. Le04:    SS0(Lf05)
  254. Le05:    SS0(Lf06)
  255. Le06:    SS0(Lf07)
  256. Le07:    SS0(Lf08)
  257. Le08:    SS0(Lf09)
  258. Le09:    SS0(Lf10)
  259. Le10:    SS0(Lf11)
  260. Le11:    SS0(Lf12)
  261. Le12:    SS0(Lf13)
  262. Le13:    SS0(Lf14)
  263. Le14:    SS0(Lf15)
  264. Le15:    SS0(Lf16)
  265. Le16:    SS0(Lf17)
  266. Le17:    SS0(Lf18)
  267. Le18:    SS0(Lf19)
  268. Le19:    SS0(Lf20)
  269. Le20:    SS0(Lf21)
  270. Le21:    SS0(Lf22)
  271. Le22:    SS0(Lf23)
  272. Le23:    SS0(Lf24)
  273. Le24:    SS0(Lf25)
  274. Le25:    SS0(Lf26)
  275. Le26:    SS0(Lf27)
  276. Le27:    SS0(Lf28)
  277. Le28:    SS0(Lf29)
  278. Le29:    SS0(Lf30)
  279. Le30:    SS0(Lf31)
  280. Le31:    SS0(Lf32)
  281. Le32:    addx    %o0,%o0,%o0
  282.     xor    %o1,-1,%o1
  283. !    st    %o1,[%o4]
  284. !    retl
  285. !    st    %o0,[%o3]
  286. ! RD, start
  287.     retl
  288.     st    %o1,[%o3]
  289. ! RD, end
  290.  
  291. Lf01:    SS1(Le02)
  292. Lf02:    SS1(Le03)
  293. Lf03:    SS1(Le04)
  294. Lf04:    SS1(Le05)
  295. Lf05:    SS1(Le06)
  296. Lf06:    SS1(Le07)
  297. Lf07:    SS1(Le08)
  298. Lf08:    SS1(Le09)
  299. Lf09:    SS1(Le10)
  300. Lf10:    SS1(Le11)
  301. Lf11:    SS1(Le12)
  302. Lf12:    SS1(Le13)
  303. Lf13:    SS1(Le14)
  304. Lf14:    SS1(Le15)
  305. Lf15:    SS1(Le16)
  306. Lf16:    SS1(Le17)
  307. Lf17:    SS1(Le18)
  308. Lf18:    SS1(Le19)
  309. Lf19:    SS1(Le20)
  310. Lf20:    SS1(Le21)
  311. Lf21:    SS1(Le22)
  312. Lf22:    SS1(Le23)
  313. Lf23:    SS1(Le24)
  314. Lf24:    SS1(Le25)
  315. Lf25:    SS1(Le26)
  316. Lf26:    SS1(Le27)
  317. Lf27:    SS1(Le28)
  318. Lf28:    SS1(Le29)
  319. Lf29:    SS1(Le30)
  320. Lf30:    SS1(Le31)
  321. Lf31:    SS1(Le32)
  322. Lf32:    addx    %o5,%o5,%o5
  323.     xor    %o1,-1,%o1
  324. !    st    %o1,[%o4]
  325. !    retl
  326. !    st    %o5,[%o3]
  327. ! RD, start
  328.     mov    %o5,%o0
  329.     retl
  330.     st    %o1,[%o3]
  331. ! RD, end
  332.  
  333.  
  334.  
  335.  
  336.  
  337.